#!/usr/bin/env bash


# clean not running images
clean_not_running_images()
{
    ALL_IMAGES=$(docker ps -a -q)
    RUN_IMAGES=$(docker ps -q)
    
    for ID in $ALL_IMAGES:
    do
        for RUN_ID in $RUN_IMAGES:
        do
            if [[ $ID != $RUN_ID ]];then
                docker rmi $ID
            fi
        done
    done
}

# 判断 str 是否存在于 arr 这个数组
# Usage: isArrayContains str "${arr[*]}"
#
isArrayContains()
{
    _arr=$2
    for i in ${_arr[@]} ;do
        if [[ $1 == "$i" ]];then
            echo 1
            return
        fi
    done
    echo 0
    return 
}

# 获取 build_ 开头的镜像,并且根据  format 显示
ALL_IMAGES=`docker images --format "{{.ID}} {{.Repository}}:{{.Tag}}" | grep -E "build_*"`
# 获取运行当中的镜像
RUN_IMAGES=`docker ps | awk 'NR>=2{print $2}' | sort | uniq`

echo "------- 获取 build_ 开头的镜像,并且根据  format 显示 -------"
echo ${ALL_IMAGES};

echo "------- 全部镜像 -------"
echo ${RUN_IMAGES};
